﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameMain : MonoBehaviour {
    public GameObject obj;
    private GridObj unitA;

    private List<GridObj> TroopB;
	// Use this for initialization
	void Start () {
        GridMap.CreateInstance(true);
        GridMap.Instance.Init(new Vector3(40,0,20), 1f, true);

        GameObject unitObj = GameObject.Instantiate<GameObject>(obj);
        unitA = unitObj.AddComponent<GridObj>();
        unitA.Init(new Vector3(20, 0, 0));

        GameObject unitObj1 = GameObject.Instantiate<GameObject>(obj);
        GridObj unitb = unitObj1.AddComponent<GridObj>();
        unitb.Init(new Vector3(0, 0, 0));

        GameObject unitObj2 = GameObject.Instantiate<GameObject>(obj);
        unitb = unitObj2.AddComponent<GridObj>();
        unitb.Init(new Vector3(5, 0, 0));

        GameObject unitObj3 = GameObject.Instantiate<GameObject>(obj);
        unitb = unitObj3.AddComponent<GridObj>();
        unitb.Init(new Vector3(10, 0, 0));

        TroopB = new List<GridObj>();
        for (int i = 0; i < 5; i++)
        {
            GameObject unitObjB = GameObject.Instantiate<GameObject>(obj);
            GridObj grid = unitObjB.AddComponent<GridObj>();
            grid.Init(new Vector3(-20, 0, 6 - i * 3));
            TroopB.Add(grid);
        }
    }

	
	// Update is called once per frame
	void Update () {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            //GridNode node = GridMap.Instance.SearchPath(unitA.transform.position, unitB.transform.position);
            //Debug.Log("Stop");
        }
        if (Input.GetKeyDown(KeyCode.W))
        {
            for (int i = 0; i < TroopB.Count; i++)
            {
                TroopB[i].MoveTo(unitA.transform.position);
            }
        }
	}
}
